#ifndef _DDXC_H
#define _DDXC_H

// #define CLIENT_BUF_SIZE 64
#define BUF_SIZE 1024
#define SEVER_BUF_SIZE BUF_SIZE
#define CLIENT_BUF_SIZE BUF_SIZE
#define NAME_SIZE 64
#define INT_SIZE 4
#define SHORT_SIZE 2
#define LONG_SIZE 8
#define CHAR_SIZE 1
#define NO_WRITE -1
#define STRING_TYPE 5
#define INT_TYPE 4
#define SHORT_TYPE 2
#define LONG_TYPE 8
#define CHAR_TYPE 1
#define GETMSG_WRITE 1

typedef struct msg{
    char buf[BUF_SIZE];
    int offset;
    int blocksize;
    long filesize;
    char type;
}msg,*msglist;



int my_recv(int sockfd,void* buf,int length);

int my_send(int sockfd,const void* buf,int length);

long file_size(const char* filename);//获取文件体积(返回文件大小)

int serializa_msg(void* node,int num);//将数值写入四个字节中（序列化

int serializa_msg_char(int sockfd,char* node,int num);//（序列化char

int serializa_msg_short(int sockfd,short* node,int num);//(序列化short)

int serializa_msg_int(int sockfd,int* node,int num);//(序列化int)

int serializa_msg_long(int sockfd,long* node,int num);//(序列化long)

int serializa_msg_block(int sockfd,char* node,int num);//(序列化字符串)

int unserializa_msg(void* node);//(反序列化)

int unserializa_msg_char(int sockfd,char* node);//(反序列化char)

int unserializa_msg_short(int sockfd,short* node);//(反序列化short)

int unserializa_msg_int(int sockfd,int* node);//(反序列化int)

int unserializa_msg_long(int sockfd,long* node);//(反序列化long)

int unserializa_msg_block(int sockfd,char* node);//(反序列化字符串)

/*
sockfd：为接收方套接字 // node:为传输数据的结构指针 //type:选择发送类型：char/short/int/long/string(流);
num:在传输string(流)的时候，num为传输的有效字节数;其他的，num为传输的具体数值;
*/
int sticky_packs_send_func(int sockfd,void* node,char type,long num);

/*
sockfd：为发送方套接字 // node:为传输数据的结构的指针 //type:用于接收，收到的数据类型：char/short/int/long/string(流);
*/
int sticky_packs_recv_func(int sockfd,void* node,char type);

void my_close(int sockfd,int clientfd);


int putmsg(int clientfd,msglist node,int fd_r);

int msg2_file(int sockfd,int clientfd,msglist node,char* name);

int msg4_send(int sockfd,int clientfd,msglist node,char* name);


int getmsg(int sockfd,msglist node,int fd_w);

int msg1_file(int sockfd,msglist node,const char* name,int nodesize);

int msg3_block(int sockfd,msglist node,const char* name);


#endif